package com.zb.test;

import com.zb.bean.Employee;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
/**
 * Stream 的三个操作步骤：
 *  1.创建Stream
 *
 *  2.中间操作
 *
 *  3.终止操作（终端操作）
 *
 */
public class JAVA8_7_StreamAPI_创建Stream {

    //创建Stream的四种方式
    @Test
    public void test(){
        //1.可以通过Collection系列集合提供的Stream() 或parallelStream()创建Stream
        List<String> list = new ArrayList<>();
        Stream<String> stream = list.stream();

        //2.通过Arrays中静态方法stream()获取数组流
        Employee[] employee = new Employee[10];
        Stream<Employee> stream1 =  Arrays.stream(employee);

        //3.通过Stream类中的静态方法of()
        Stream<String> stream2 = Stream.of("a","b","1");

        //4.创建一个无限流
        //迭代
        Stream<Integer> stream3 = Stream.iterate(0,x->x+2);
        stream3.limit(10).forEach(System.out::println);
        //生成
        Stream<Double> stream4 = Stream.generate(Math::random);
        stream4.limit(10).forEach(System.out::println);
    }
}
